<?php
declare (strict_types = 1);

namespace app\middleware;
use think\Cache;
use think\facade\Session;

class Check
{

    public function handle($request, \Closure $next)
    {

         // 记住当前地址并重定向
        if (\session('admin_id') < 1 || is_null(\session('admin_id'))) {

            $url=url('Login/login');
            //$js = "<script>window.top.location.href='$url'</script>";
           // echo $js;

            return Redirect("$url")->with('message', '请先登录');
        }
        $check=checkPer();
        if(!$check){
           return json(['code'=>400,'msg'=>'无权限操作']);
        }

        return $next($request);
    }
}
